/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author eleven
 */
public class ActionFactory {

    protected Map map = defaultMap();
    private String nameAction = null;

    public ActionFactory(String nameAction) {
        this.nameAction = nameAction;
    }

    public Action getAction() {
        Class classAction = (Class) map.get(this.nameAction);
        if (classAction != null) {
            try {
                return (Action) (classAction.newInstance());
            } catch (Exception exc) {
                exc.printStackTrace();
            }
        }
        return null;
    }

    Map defaultMap() {
        Map map = new HashMap();
        map.put("calculate", CalculateAction.class);
        map.put("upload", UploadAction.class);
        return map;
    }
}
